package com.team7.happycommunity.propertymanagement.service.impl;

import com.team7.happycommunity.propertymanagement.dao.ParkingInfoMapper;
import com.team7.happycommunity.propertymanagement.dao.PropertyManageMapper;
import com.team7.happycommunity.propertymanagement.pojo.ParkingInfo;
import com.team7.happycommunity.propertymanagement.pojo.PropertyManage;
import com.team7.happycommunity.propertymanagement.service.ParkingInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class ParkingInfoServiceImpl implements ParkingInfoService {

    @Autowired
    ParkingInfoMapper parkingInfoMapper;

    @Autowired
    PropertyManageMapper propertyManageMapper;



    @Override
    public List<ParkingInfo> getList(Integer currentPage, Integer pageSize, String username) {
        PropertyManage propertyManage = propertyManageMapper.selectByUserName(username);
        int areaId = propertyManage.getVillageId();
        return parkingInfoMapper.selectByPageAndareaId(currentPage,pageSize,areaId);
    }

    @Override
    public int save(ParkingInfo parkingInfo, String username) {
        if(parkingInfo.getId() == null){
            PropertyManage propertyManage = propertyManageMapper.selectByUserName(username);
            propertyManage.getId();
            propertyManage.getVillageId();
            parkingInfo.setCommunityId(propertyManage.getVillageId());
            parkingInfo.setOwnerId(propertyManage.getId());
            parkingInfo.setType(0);
            return parkingInfoMapper.insertSelective(parkingInfo);
        }else{
            return parkingInfoMapper.updateByPrimaryKeySelective(parkingInfo);
        }

    }

    @Override
    public int delete(Integer id) {
        ParkingInfo parkingInfo = new ParkingInfo();
        parkingInfo.setId(id);
        // 设置状态为下架
        parkingInfo.setStatus(1);

        return parkingInfoMapper.updateByPrimaryKeySelective(parkingInfo);
    }

    @Override
    public List<ParkingInfo> getMList(Integer areaid) {

        return parkingInfoMapper.selectByAreaId(areaid);
    }
}
